#include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
    /**
     * 计算你能获得的最大收益
     * 
     * @param v v[i]即第i天的股价
     * @return 整型
     */
    int calculateMax(vector<int> v) {
    	int max = 0;
    	for(int i = 0 ; i < v.size() ; ++i)
    		max = max > (findMax(v,0,i)+findMax(v,i+1,v.size()-1))? max : (findMax(v,0,i)+findMax(v,i+1,v.size()-1));
    	return max;
    }


    int findMax(const vector<int> &v,int bg,int ed)
    {
    	int max = 0;
    	int start = v[bg];
    	for(int i = bg ; i <= ed ; ++i)
    	{
    		if(start > v[i])
    			start = v[i];
    		else if(v[i] - start > max)
    			max = v[i] - start;
    	}
    	return max;
    }
    void printV(const vector<int> &v)
    {
    	for(int i : v)
    		cout<<i<<',';
    	cout<<endl;
    }
};

int main()
{
	Solution s;
	cout<<s.calculateMax(vector<int>{1,10,2,12})<<endl;
	return 0;
}